import { sleepSync } from '~/utils'
import { setUserInfo, getUserInfo, removeUserInfo } from '~/utils/auth'

export const useLogin = () => {
    const {
        setToken,
        removeToken
    } = useToken()

    const isLogin = useState('isLogin')
    const updateLogin = async (token: string) => {
        setToken(token)
        isLogin.value = true
        await sleepSync()
    }
    const doLogout = () => {
        removeToken()
        isLogin.value = false
        removeUserInfo()
    }
    return {
        updateLogin,
        doLogout
    }
}
